/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2022-11-26
 * Time: 18:36
 */
public class Test {
    public static boolean isAdmin(String userId){
        return userId.toLowerCase()=="admin";//左侧new了一个对象，右侧在常量池，==比较的是地址，指向不同尾false
    }
    public static void main(String[] args) {
//        boolean a = isAdmin("Admin");
//        System.out.println(a);
        String s1="abc"+"def";//1
        String s2=new String(s1);//2
        if(s1.equals(s2))//3
            System.out.println(".equals succeeded");//4
        if(s1==s2)//5
            System.out.println("==succeeded");//6
    }
}
//https://leetcode.cn/problems/number-of-segments-in-a-string/submissions/
//class Solution {
//    public int countSegments(String s) {
//        if (s == null || s.length() == 0)
//            return 0;
//        int ans = 0;
//        //以空格为分隔符，提取String单词组
//        String[] strs = s.split(" ");
//        for (String x : strs)
//            //遍历排除空String
//            if (x.length() != 0)
//                ans++;
//
//        return ans;
//    }
//}

//class Solution {
//    public int countSegments(String s) {
//        int ans = 0;
//        for (int i = 0; i < s.length(); i++){
//            //第一个单词特殊，特殊讨论
//            //之后的单词都是前空格，后字母
//            if ((i == 0 || s.charAt(i - 1) == ' ') && s.charAt(i) != ' ')
//                ans++;
//        }
//        return ans;
//    }
//}

